﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace KZ400B
{
    public enum AxleStatus
    {

        Stoped = 0,
        Respond = 1,
        Running = 2,
    }
    public enum AxleActions
    {
        Succeed = 0,
        Failed = 1,

        Executing = 2,


        ToZero = 3,
        Run = 4,
        Stop = 5,
        RelativeZero = 6,
        Query = 7,
        QueryPosition = 8,
        StepperAngleFraction = 9,
        ParameterPreserve = 10,
        VZero = 11,


        ContactRespond = 20,
        ParameterSettingRespond = 21,
        AccelerationSettingRespond = 22,
        ToZeroRespond = 23,
        RunRespond = 24,
        StopRespond = 25,
        RelativeZeroRespond = 26,
        QueryRespond = 27,
        QueryPositionRespond = 28,
        StepperAngleFractionRespond = 29,
        ParameterPreserveRespond = 30,
        VZeroRespond = 31,

        ToZeroFinish = 43,
        RunFinish = 44,
        StopFinish = 45,
        RelativeZeroFinish = 46,
        VZeroFinish = 51,

        QueryFinish = 57,
        QueryPositionFinish = 58,

        VZeroSetFinish = 70,
        VZeroRemoveFinish = 71,
        VZeroFailed = 72,



        ToZeroError = 83,
        RunError = 84,
        StopError = 85,
        RelativeZeroError = 86,
        
        QueryError = 87,
        QueryPositionError = 88,
        VZeroError = 91,




        WrongFormat = 178,

        Exception = 180,

        AllActions = 0xef
    }
    
    public delegate void AxleActionResponse(string axleName,Axle axle,AxleActions action,bool success,string message);
    public class AxleAction
    {
        AxleActions m_action;

        public AxleActions Action
        {
            get { return m_action; }
            set { m_action = value; }
        }
        List<string> m_axleList;

        public List<string> AxleList
        {
            get { if(m_axleList == null){m_axleList = new List<string>();} return m_axleList; }
        }
        bool m_result;

        public bool Result
        {
            get { return m_result; }
            set { m_result = value; }
        }

        public void Add(string axleName)
        {
            if (m_axleList == null) { m_axleList = new List<string>(); }
            m_axleList.Add(axleName);
        }
    }
    public enum AxleSpeeds
    { 
        Constant = 0,/** 匀速 **/
        GatherWay = 1/** 加速 **/
    }
    public enum AccelerationSpeeds
    {
        Constant = 0,/** 匀速 **/
        GatherWay = 1/** 加速 **/
    }

    public enum TozeroSpeeds
    {
        Constant = 0,/** 匀速 **/
        GatherWay = 1/** 加速 **/
    }
    public partial class Axle
    {
        public const string AllAxleName = "A";
        public Axle(string name)
        {
            m_ASlk = new object();
            m_OtherASlk = new object();
            m_ID = 0;
            m_Name = name;
            m_Position = 0;
            m_axleActionStatus = new AxleActionStatus(name);
        }


        protected AxleActionStatus m_axleActionStatus;

        public AxleActionStatus AxleActionStatus
        {
            get { if (m_axleActionStatus == null) { m_axleActionStatus = new AxleActionStatus(m_Name); } return m_axleActionStatus; }
            set { m_axleActionStatus = value; }
        }

        public Axle(DB.Model.Axle ax)
        {
            m_ASlk = new object();
            m_OtherASlk = new object();

            m_ID = ax.ID;
            m_Name = ax.Name;
            m_PowerShiftStation = ax.PowerShiftStation == null 
                ? PowerShiftStations.NoConnected
                :(PowerShiftStations) ax.PowerShiftStation.Value;

            m_RunningUnit = ax.RunningUnit == null
                        ? RunningUnits.Step
                        : (RunningUnits)ax.RunningUnit.Value;

            m_RelativeZero = ax.RelativeZero ?? 0;
            m_LeadDistance = ax.LeadDistance ?? 0;
            m_DriveRatio = ax.DriveRatio ?? 0;
            m_AxleDetailSetting = ax.AxleDetailSetting ?? 1;
            m_Radian = ax.Radian ?? 1.8;
            m_runSpeed = ax.RunSpeed ?? 0.0F;
            m_tozeroSpeed = ax.TozeroSpeed ?? 0.0F;
            m_Position = ax.Position ?? 0.0F;

            m_runacceleration = ax.RunAcceleration;
            m_onestepaddtion = ax.OneStepAddtion;
            m_runtarget = ax.RunTarget;
            
        }

        public DB.Model.Axle DBModel
        {
            get {
                DB.Model.Axle ax = new DB.Model.Axle();
                ax.ID = m_ID;
                ax.Name = m_Name;
                ax.PowerShiftStation = (int)m_PowerShiftStation;

                ax.RunningUnit = (int)m_RunningUnit;

                ax.RelativeZero = m_RelativeZero;
                ax.LeadDistance = m_LeadDistance;
                ax.DriveRatio = m_DriveRatio;
                ax.AxleDetailSetting = m_AxleDetailSetting;
                ax.Radian = m_Radian;
                ax.RunSpeed = m_runSpeed;
                ax.TozeroSpeed = m_tozeroSpeed;
                ax.Position = m_Position;

                ax.RunAcceleration = m_runacceleration;
                ax.OneStepAddtion = m_onestepaddtion;
                ax.RunTarget = m_runtarget;

                return ax;
            }
        }

        private AxleStatus m_AxleStatus;
        private object m_ASlk;
        public AxleStatus AxleStatus
        {
            get { lock (m_ASlk) { return m_AxleStatus; } }
            set { lock (m_ASlk) { if (m_AxleStatus != value) { m_AxleStatus = value; } } }
        }

        private bool m_IsToZeroed;

        public bool IsToZeroed
        {
            get { return m_IsToZeroed; }
            set { m_IsToZeroed = value; }
        }


        private AxleActions m_OtherAxleStatus;
        private object m_OtherASlk;
        public AxleActions OtherAxleStatus
        {
            get { lock (m_OtherASlk) { return m_OtherAxleStatus; } }
            set { lock (m_OtherASlk) { if (m_OtherAxleStatus != value) { m_OtherAxleStatus = value; } } }
        }


        private int m_ID;

        public int ID
        {
            get { return m_ID; }
            set { m_ID = value; }
        }
         

        private string m_Name;
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

      //  public static readonly DependencyProperty IsSpinningProperty =
      //DependencyProperty.Register("Position", typeof(int), typeof(Axle));
        //event AxlePositionChange m_EventPositionChanged;
        private double m_Position;
        public double Position
        {
            get { return m_Position; }
            set
            {
                if (value != m_Position)
                {
                    //if (m_EventPositionChanged != null)
                    //{
                    //    m_EventPositionChanged(this.m_Name, this, value);
                    //}
                }
                m_Position = value;
            }
        }

        public double  DisplayPosition
        {
            get {
                double np = m_Position;
                double nrzero = m_RelativeZero;
                if (m_RunningUnit != RunningUnits.Step)
                { 
                    np = np * OnestepDisplacement;
                    nrzero = nrzero * OnestepDisplacement;
                }

                return np - nrzero;
            }
            
        }

        //数据单位转换 step->毫米
        public  double UnitStep2MM(double step)
        {
            double mm = 0F;
            mm = step * OnestepDisplacement;
            return mm;
        }

        //数据单位转换 step->度数
        public  double UnitStep2R(double step)
        {
            double r = 0F;
            r = step * OnestepDisplacement;
            return r;
        }


        //数据单位转换 毫米->step
        public  double UnitMM2Step(double mm)
        {
            double step = 0F;
            if (OnestepDisplacement != 0)
            {
                step = mm / OnestepDisplacement;
            }
            return step;
        }


        //数据单位转换 度数->step
        public  double UnitR2Step(double rd)
        {
            double step = 0F;
            if (OnestepDisplacement != 0)
            {
                step = rd / OnestepDisplacement;
            }
            return step;
        }


        public double DisplayRelativeZero
        {
            get
            {
                double nrzero = m_RelativeZero;
                if (m_RunningUnit != RunningUnits.Step)
                {
                    nrzero = nrzero * OnestepDisplacement;
                }

                return nrzero;
            }

        }

        public static double DefaultPosition
        {
            get { return -99999999999999.9898999999F; }
        }
        public static double ComputeRelativePosition(double position,double relativeZero)
        {
            double ps = position;
            if (position >= 0)
            {
                if (relativeZero > 0)
                {
                    ps = position - relativeZero;
                }
                else
                {
                    ps = position + relativeZero;
                }
            }
            else
            {
                if (relativeZero > 0)
                {
                    ps = position + relativeZero;
                }
                else
                {
                    ps = position - relativeZero;
                }
            }
            return ps;
        }

        /// <summary>
        /// 电移台
        /// </summary>
        private PowerShiftStations m_PowerShiftStation;
        /// <summary>
        /// 电移台
        /// </summary>
        public PowerShiftStations PowerShiftStation
        {
            get { return m_PowerShiftStation; }
            set { m_PowerShiftStation = value; }
        }
        /// <summary>
        /// 运行单位
        /// </summary>
        private RunningUnits m_RunningUnit;
        /// <summary>
        /// 运行单位
        /// </summary>
        public RunningUnits RunningUnit
        {
            get { return m_RunningUnit; }
            set { m_RunningUnit = value; }
        }
        /// <summary>
        /// 各轴相对零位[RelativeZero](int)
        /// </summary>
        private double m_RelativeZero;
        /// <summary>
        /// 各轴相对零位[RelativeZero](int)
        /// </summary>
        public double RelativeZero
        {
            get { return m_RelativeZero; }
            set { m_RelativeZero = value; }
        }


        /// <summary>
        /// 丝杆导程(double)[LeadDistance ]
        /// </summary>
        private double m_LeadDistance;
        /// <summary>
        /// 丝杆导程(double)[LeadDistance ]
        /// </summary>
        public double LeadDistance
        {
            get { return m_LeadDistance; }
            set { m_LeadDistance = value; }
        }
        /// <summary>
        /// 传动比(double)[DriveRatio]
        /// </summary>
        private double m_DriveRatio;
        /// <summary>
        /// 传动比(double)[DriveRatio]
        /// </summary>
        public double DriveRatio
        {
            get { return m_DriveRatio; }
            set { m_DriveRatio = value; }
        }
        /// <summary>
        /// 细分数设置(int)[AxleDetailSetting] 
        /// 挡位1、2、3代表细分数，5、6、7代表电流值
        /// </summary>
        private int m_AxleDetailSetting = 1;
        /// <summary>
        /// 细分数设置(int)[AxleDetailSetting] 
        /// 挡位1、2、3代表细分数，5、6、7代表电流值
        /// </summary>
        public int AxleDetailSetting
        {
            get { return m_AxleDetailSetting; }
            set { m_AxleDetailSetting = value; }
        }
        /// <summary>
        /// 电移台电机度数[Radian]//1.8,0.9
        /// </summary>
        private double m_Radian = 1.8;
        /// <summary>
        /// 电移台电机度数[Radian]//1.8,0.9
        /// </summary>
        public double Radian
        {
            get { return m_Radian; }
            set { m_Radian = value; }
        }
        //单步运行位移[OnestepDisplacement]
        //private double m_OnestepDisplacement;
        /// <summary>
        /// 单步运行位移[OnestepDisplacement]
        /// </summary>
        public double OnestepDisplacement
        {
            get { return ComputeOneStepDisplacement(); }
        }

        public double TotalStep
        {
            get {
                if (m_RunningUnit == RunningUnits.UnDefined) { return 0.0F; }
                return m_RunningUnit == RunningUnits.Step
                ? m_addtion
                : (double)(m_addtion / OnestepDisplacement);
            }
        }

        /// <summary>
        /// 平移台:
        /// 丝杆导程 1，细分数设定：8，单步运行的位移 = 1/(200*8) = 0.000625 ;
        /// 丝杆导程 P，细分数设定：n，单步运行的位移 = P/(200*n) ;
        /// 
        /// 旋转台:
        /// 单步运行位移 = 电移台电机度数 / 【传动比（旋转台）×细分数设定】
        /// </summary>
        /// <returns></returns>
        public double ComputeOneStepDisplacement()
        {
            
                double onestep = 0.0;
                
                if (PowerShiftStation == PowerShiftStations.Translational)
                {
                    double rx = 360 / m_Radian;
                    onestep = m_LeadDistance / (rx * m_AxleDetailSetting);
                }
                else if (PowerShiftStation == PowerShiftStations.Whirling)
                {
                    onestep = m_Radian / (m_DriveRatio * m_AxleDetailSetting);
                }
                return onestep;
 
        }

        /// <summary>
        /// 运行周期
        /// </summary>
        /// <param name="speed"></param>
        /// <returns></returns>
        public double getRunPwm(double speed)
        {

            double onestep = 0.0F;
            if (m_RunningUnit == RunningUnits.UnDefined)
            {
                throw new Exception(string.Format("请设定运行单位"));
            }
            double nSpeed = speed;
            if (m_RunningUnit == RunningUnits.Step)
            {
                nSpeed = UnitStep2MM(speed);
            }
            //else if (m_RunningUnit == RunningUnits.Step)
            //{
            //    onestep = 1.0F;//m_addtion;
            //}
            //else
            { onestep = ComputeOneStepDisplacement(); }
                
                double pwm = onestep / nSpeed * 1000 * 1000;
                if (pwm < MySetting.RunPWMLimit)
                {
                    throw new Exception(string.Format("运行周期 应该大于 {0} us",MySetting.RunPWMLimit));
                }
                return pwm;

        }

        /// <summary>
        /// 运行周期 应该大于20 us
        /// </summary>
        public double RunPWM
        {
            get { return getRunPwm(m_runSpeed); }
        }

        public double ComputeAddtion(double target, ref int dir)
        {
            double nt = target;
            dir = Axle.Direction.ForwardDirection.Value;
            double pos = Position;
            double rZero = m_RelativeZero;
            if (m_RunningUnit != RunningUnits.Step)
            {
                rZero = rZero * OnestepDisplacement;
                pos = pos * OnestepDisplacement;

                //target = target * OnestepDisplacement;
            }
            else
            {
                if (OnestepDisplacement != 0)
                {
                    target = target / OnestepDisplacement;
                }
            }
            if ((nt + rZero) < 0)
            {
                //if (nt > (m_Axle.Position + m_Axle.RelativeZero))
                {
                    throw new Exception("运行目标超越绝对零位!");
                }
            }
            //if (pos != 0.0F && rZero != 0)
            if (rZero != 0)
            {
                pos = ComputeRelativePosition(pos, rZero);
            }
            if (nt == pos)
            {
                return 0;
            }
            else if (nt < pos)
            {
                if (nt < 0)
                {
                    nt = 0 - target;
                    //if (m_Axle.RelativeZero > 0)
                    //{
                    //    nt += m_Axle.RelativeZero;
                    //}
                    nt += pos;// +m_Axle.RelativeZero;

                }
                else
                {
                    nt -= pos;
                }
                if (nt < 0)
                {
                    nt = 0 - nt;
                }
                dir = Axle.Direction.BackDirection.Value;
            }
            else
            {
                if (rZero < 0)
                {
                    throw new Exception("绝对零位不能小于0!");
                    nt -= rZero;
                }
                nt -= pos;// +m_Axle.RelativeZero;
            }
            return nt;
        }

        /// <summary>
        /// 归零周期 必须大于 14 us
        /// </summary>
        /// <param name="speed"></param>
        /// <returns></returns>
        public double getTozeroPwm(double speed)
        {

            double nSpeed = speed;
            if (m_RunningUnit == RunningUnits.Step)
            {
                nSpeed = UnitStep2MM(speed);
            }
                double onestep = ComputeOneStepDisplacement();
                double pwm = onestep / nSpeed * 1000 * 1000;
                if (pwm < MySetting.ToZeroPWMLimit)
                {
                    throw new Exception(string.Format("归零周期应该大于 {0} us",MySetting.ToZeroPWMLimit));
                }
                return pwm;
     
        }
        /// <summary>
        /// 归零周期 必须大于 44 us
        /// </summary>
        /// <returns></returns>
        public double TozeroPWM
        {
            get { return getTozeroPwm(m_tozeroSpeed); }
        }


        //---运行参数
        //增量
        private double m_addtion;

        public double Addtion
        {
            get { return m_addtion; }
            set { m_addtion = value; }
        }
        
        /// <summary>
        /// 单步增量
        /// </summary>
        private int m_onestepaddtion = 0;

        public int OnestepAddtion
        {
            get { return m_onestepaddtion; }
            set { m_onestepaddtion = value; }
        }
        
        /// <summary>
        /// 运行目标
        /// </summary>
        private double m_runtarget = 0;

        public double RunTarget
        {
            get { return m_runtarget; }
            set { m_runtarget = value; }
        }

        ///<summary>
        ///加速度
        ///</summary>
        private int m_runacceleration = 0;

        public int RunAcceleration
        {
            get { return m_runacceleration; }
            set { m_runacceleration = value; }
        }
        //运行周期

        private double m_runSpeed;
        /// <summary>
        /// 运行速度
        /// </summary>
        public double RunSpeed
        {
            get { return m_runSpeed; }
            set { m_runSpeed = value; }
        } 
        //归零速度
        private double m_tozeroSpeed;
        /// <summary>
        /// 归零速度
        /// </summary>
        public double TozeroSpeed
        {
            get { return m_tozeroSpeed; }
            set { m_tozeroSpeed = value; }
        }


        public class Direction
        {
            private const int d_forward = 0;
            private const int d_backward = 1;

            private int m_direction = d_forward;

            public Direction(int direction)
            {
                if (direction == d_forward || direction == d_backward)
                { m_direction = direction; }
            }

            private static Direction s_fObj = new Direction(d_forward);
            private static Direction s_bObj = new Direction(d_backward);
            public static Direction ForwardDirection { get { return s_fObj; } }
            public static Direction BackDirection { get { return s_bObj; } }


            public static string Forward { get { return d_forward.ToString(); } }
            public static string Backward { get { return d_backward.ToString(); } }

            public int Value
            {
                get { return m_direction;}
            }

            public override string ToString()
            {
                return m_direction.ToString();
                //switch (m_direction)
                //{
                //    case d_forward:
                //        return "+";//"Forward";
                //    case d_backward:
                //        return "-";//"Backward";
                //    default:
                //    return m_direction.ToString();
                //}
            }
        }

        /// <summary>
        /// 运行速度,范围 0 - 99 
        /// </summary>
        public class RunningSpeedConverter
        {
            public static string GetRunningSpeed(int runningSpeed)
            {
                //if (runningSpeed >= 0 && runningSpeed <= 1)
                //{
                //    //return runningSpeed.ToString("00");
                //    return ((AxleSpeed)runningSpeed).ToString()[0].ToString();
                //}
                //throw new OverflowException("runningSpeed must between 0 to 99");
                return GetRunningSpeed((AxleSpeeds)runningSpeed);
            }

            public static string GetRunningSpeed(AxleSpeeds runningSpeed)
            {
                if ((int)runningSpeed >= 0 && (int)runningSpeed <= 1)
                {
                    //return runningSpeed.ToString("00");
                    return runningSpeed.ToString()[0].ToString();
                }
                throw new OverflowException("runningSpeed must between C to G");
            }
        }

        public class RunningPeriodConverter
        {
            public static string GetRunningPeriod(double period)
            {
                if (period >= MySetting.RunPWMLimit)
                {
                    return ((int)period).ToString();
                }
                //throw new OverflowException("runningSpeed must greater than 20");
                return MySetting.RunPWMLimit.ToString();
            }
        }


        /// <summary>
        /// 目标步长,范围 0 - 99999999
        /// </summary>
        public class TargetStepConverter
        {
            public static string GetTargetStep(double targetStep)
            {
                if (targetStep >= 0 && targetStep <= 99999999)
                {
                    return ((int)targetStep).ToString();
                }
                throw new OverflowException("runningSpeed must between 0 to 99999999");
            }
        }

        /// <summary>
        /// 加速度
        /// </summary>
        public class AccelerationLevel
        {
            //public static string Low            { get { return "L"; } }//低
            //public static string Mid            { get { return "M"; } }//中
            //public static string High           { get { return "H"; } }//高
            //public static string Unlimite       { get { return "G"; } }//无穷
            public static int Constant   { get { return (int)AccelerationSpeeds.Constant; } }//匀速
            public static int GatherWay  { get { return (int)AccelerationSpeeds.GatherWay; } }//加速
            public static int Empty          { get { return Constant;} }

            private int m_AccelerationLevel = Constant;
            public AccelerationLevel(AccelerationLevel aLevel)
            {
                m_AccelerationLevel = aLevel.m_AccelerationLevel;
            }

            public int IntValue
            { get { return m_AccelerationLevel; } }

            public AccelerationLevel(int aLevel)
            {
                if (aLevel.Equals(Constant))
                {
                    m_AccelerationLevel = Constant;
                }
                else if (aLevel.Equals(GatherWay))
                {
                    m_AccelerationLevel = GatherWay;
                }
                else
                {
                    m_AccelerationLevel = Empty;
                }
            }

            //public AccelerationLevel(string aLevel)
            //{
            //    if (string.IsNullOrEmpty(aLevel))
            //    {
            //        m_AccelerationLevel = Empty;
            //    }
            //    if (aLevel.Equals(Constant))
            //    {
            //        m_AccelerationLevel = Constant;
            //    }
            //    else if (aLevel.Equals(GatherWay))
            //    {
            //        m_AccelerationLevel = GatherWay;
            //    }
            //    //if (aLevel.Equals(Low))
            //    //{
            //    //    m_AccelerationLevel = Low;
            //    //}
            //    //else if (aLevel.Equals(Mid))
            //    //{
            //    //    m_AccelerationLevel = Mid;
            //    //}
            //    //else if (aLevel.Equals(High))
            //    //{
            //    //    m_AccelerationLevel = High;
            //    //}
            //    //else if (aLevel.Equals(Unlimite))
            //    //{
            //    //    m_AccelerationLevel = Unlimite;
            //    //}
            //    else
            //    {
            //        m_AccelerationLevel = Empty;
            //    }
            //}

            public override string ToString()
            {
                return ((AccelerationSpeeds)m_AccelerationLevel).ToString()[0].ToString();
            }

            //private static AccelerationLevel s_LowObj = new AccelerationLevel(Low);
            //public static AccelerationLevel AccelerationLevelLow{ get { return AccelerationLevel.s_LowObj; } }


            //private static AccelerationLevel s_MidObj = new AccelerationLevel(Mid);
            //public static AccelerationLevel AccelerationLevelMid { get { return AccelerationLevel.s_MidObj; } }


            //private static AccelerationLevel s_HighObj = new AccelerationLevel(High);
            //public static AccelerationLevel AccelerationLevelHigh { get { return AccelerationLevel.s_HighObj; } }


            //private static AccelerationLevel s_unlimitObj = new AccelerationLevel(Unlimite);
            //public static AccelerationLevel AccelerationLevelUnlimite { get { return AccelerationLevel.s_unlimitObj; } }

            private static AccelerationLevel s_ConstantObj = new AccelerationLevel(Constant);
            public static AccelerationLevel AccelerationLevelConstant { get { return AccelerationLevel.s_ConstantObj; } }

            private static AccelerationLevel s_GatherWayObj = new AccelerationLevel(GatherWay);
            public static AccelerationLevel AccelerationLevelGatherWay { get { return AccelerationLevel.s_GatherWayObj; } }

        }


        /// <summary>
        /// 归零速度,范围6档 1-6
        /// </summary>
        public class ToZeroSpeed
        {
            public static int Constant   { get { return (int)TozeroSpeeds.Constant; } }//匀速
            public static int GatherWay  { get { return (int)TozeroSpeeds.GatherWay; } }//加速
            public static int Empty          { get { return Constant;} }

            private int m_sp = Constant;
            public ToZeroSpeed(ToZeroSpeed aLevel)
            {
                m_sp = aLevel.m_sp;
            }

            public ToZeroSpeed(int speed)
            {
                if (speed.Equals(Constant))
                {
                    m_sp = Constant;
                }
                else if (speed.Equals(GatherWay))
                {
                    m_sp = GatherWay;
                }
                else
                {
                    m_sp = Empty;
                }
            }


            private static ToZeroSpeed s_ConstantObj = new ToZeroSpeed(Constant);
            public static ToZeroSpeed ToZeroSpeedConstant { get { return ToZeroSpeed.s_ConstantObj; } }

            private static ToZeroSpeed s_GatherWayObj = new ToZeroSpeed(GatherWay);
            public static ToZeroSpeed ToZeroSpeedGatherWay { get { return ToZeroSpeed.s_GatherWayObj; } }

            public override string ToString()
            {
                return ((TozeroSpeeds)m_sp).ToString()[0].ToString();
            }

            //public const int LevelMin = 1;
            //public const int LevelMax = 6;
            //public static int Level1 { get { return 1; } }
            //public static int Level2 { get { return 2; } }
            //public static int Level3 { get { return 3; } }
            //public static int Level4 { get { return 4; } }
            //public static int Level5 { get { return 5; } }
            //public static int Level6 { get { return 6; } }
            //public static int Empty { get { return 0; } }


            //public static string Constant { get { return "C"; } }//匀速
            //public static string GatherWay { get { return "G"; } }//加速
            //public static string Empty { get { return string.Empty; } }


            //private static ToZeroSpeed s_ConstantObj = new ToZeroSpeed(Constant);
            //public static ToZeroSpeed ToZeroSpeedConstant { get { return ToZeroSpeed.s_ConstantObj; } }

            //private static ToZeroSpeed s_GatherWayObj = new ToZeroSpeed(GatherWay);
            //public static ToZeroSpeed ToZeroSpeedGatherWay { get { return ToZeroSpeed.s_GatherWayObj; } }

            //private string m_ToZeroSpeed = string.Empty;
            //public string Speed { get { return m_ToZeroSpeed; } }

            //public ToZeroSpeed(ToZeroSpeed speed)
            //{
            //    m_ToZeroSpeed = speed.m_ToZeroSpeed;
            //}

            //public ToZeroSpeed(string speed)
            //{

            //    if (string.IsNullOrEmpty(speed))
            //    {
            //        m_ToZeroSpeed = Empty;
            //    }
            //    if (speed.Equals(Constant))
            //    {
            //        m_ToZeroSpeed = Constant;
            //    }
            //    else if (speed.Equals(GatherWay))
            //    {
            //        m_ToZeroSpeed = GatherWay;
            //    }
            //}

            //public ToZeroSpeed(int speed)
            //{
            //    if (speed >= LevelMin && speed <= LevelMax)
            //    {
            //        m_ToZeroSpeed = speed;
            //    }
            //    else
            //    {
            //        m_ToZeroSpeed = 0;
            //    }
            //}

            //public override string ToString()
            //{
            //    //if (m_ToZeroSpeed >= LevelMin && m_ToZeroSpeed <= LevelMax)
            //    //{
            //    //    return m_ToZeroSpeed.ToString();
            //    //}
            //    //else
            //    //{
            //    //    return string.Empty;
            //    //}
            //    return m_ToZeroSpeed;
            //}
        }
    }
}
